<%@ page import="java.util.List" %>
<%@ page import="entity.Permission" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="entity.Modular" %><%--
  Created by IntelliJ IDEA.
  User: zhouya
  Date: 2019/6/26/0026
  Time: 1:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%
        List<Modular> list1=(List<Modular>)request.getAttribute("list1");//所有的权力
        List<Modular> list2=(List<Modular>)request.getAttribute("list2");//该角色的权力
        String characterID = (String) request.getAttribute("characterID");
        List<Integer> isGet=new ArrayList<>();
        for(Modular ls1:list1){
            int flag=0;
            for (Modular ls2:list2){
                if(ls1.getModularId()==ls2.getModularId()) {
                    flag = 1;
                    break;
                }
            }
            isGet.add(flag);
        }
    %>

    <script>
        function savePermission() {
            var input = document.getElementsByTagName("input");
            var str = "";
            for (var i = 0; i < input.length; i++) {
                var obj = input[i];
                //判断是否是checkbox并且已经选中
                if (obj.type == "checkbox" && obj.checked)
                {
                    var code = obj.value;//获取checkbox的值
                    str=str+code+",";
                }
            }
            document.getElementById("permissions").value = str;
            alert("修改成功");
            return true;
        }
    </script>
</head>
<body>
    <form action="PermissionSaveServlet" method="post">
        <%for(int i=0;i<list1.size();i++){%>
                <input type="checkbox" id=<%=list1.get(i).getModularId()%> value="<%=list1.get(i).getModularId() %>"
                       <%if(isGet.get(i)==1){%>checked<%}%> />
                <%=list1.get(i).getmName()%><br>
        <%}%>
        <input type="text" style="display: none;" name="characterId" value="<%=characterID%>">
        <input type="text" style="display: none" name="permissions" id="permissions" />
        <input type="submit" onclick="return savePermission()" value="确定修改" />
    </form>
</body>
</html>
